import 'package:flutter/material.dart';

class BuildItem extends StatelessWidget {
  final IconData icon;
  final String title;
  final VoidCallback? ontap;
  final String? badge;
  final String? label;
  final Widget? trailing;

  const BuildItem({
    super.key,
    required this.icon,
    required this.title,
    this.ontap,
    this.badge,
    this.label,
    this.trailing,
  });

  @override
  Widget build(BuildContext context) {
    return Material(
      child: InkWell(
        onTap: ontap,
        splashColor: Colors.grey.withOpacity(0.3), // 水波纹颜色
        highlightColor: Colors.grey.withOpacity(0.1), // 按压高亮色
        child: Container(
          color: Theme.of(context).scaffoldBackgroundColor,
          padding: const EdgeInsets.symmetric(
            vertical: 0,
            horizontal: 12,
          ),
          height: 48,
          child: Row(
            children: [
              Icon(
                icon,
                color: Theme.of(context).primaryColor,
                size: 18,
              ),
              const SizedBox(width: 8),
              Expanded(
                child: Text(
                  title,
                  style: Theme.of(context).textTheme.bodyLarge,
                ),
              ),
              trailing ?? const SizedBox.shrink(),
              label != null
                  ? Text(
                      '$label',
                      style: Theme.of(context).textTheme.bodyMedium,
                    )
                  : const SizedBox.shrink(),
              badge != null
                  ? Container(
                      margin: const EdgeInsets.only(left: 6),
                      padding: const EdgeInsets.symmetric(
                          horizontal: 6, vertical: 2),
                      decoration: BoxDecoration(
                        // 固定
                        color: Colors.red,
                        borderRadius: BorderRadius.circular(12),
                      ),
                      child: Text(
                        '$badge',
                        style: const TextStyle(
                          fontSize: 10,
                          // 固定
                          color: Colors.white,
                        ),
                      ),
                    )
                  : const SizedBox.shrink(),
            ],
          ),
        ),
      ),
    );
  }
}
